home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5719 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: printing pid_t...
  5. Date: 21 Feb 96 10:28:33 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.824898513@rscernix>
  8. References: <4gcv6f$6jf@cisunix1.dfci.harvard.edu>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <4gcv6f$6jf@cisunix1.dfci.harvard.edu> gotd@jimmy.harvard.edu (Godfrey Degamo) writes:
  13.  
  14. >Hello.  Sorry to bother you with this question.  I don't know
  15. >if this belongs in comp.unix.programmers or here.
  16.  
  17. comp.unix.programmer would have been probably better, but the answer
  18. doesn't involve any (other) Unix-specific features, so here it goes:
  19.  
  20. [the c.l.c purist is kindly asked to mentally replace pid_t by size_t :-)]
  21.  
  22. >Anyways, I want to read and write pid_t to a text file.  The problem
  23. >is how is pid_t type defined?  As an int, long, unsigned int or
  24. >unsigned long.  
  25.  
  26. If there was a unique definition for pid_t, pid_t wouldn't have existed
  27. in the first place.  The purpose of these types is to hide the real
  28. definition, which can differ from system to system.
  29.  
  30. >Can I be safe to assume unsigned long and use %lu for printing and
  31. >scanning?
  32.  
  33. This is a safe assumption, as long as you deal only with text streams.
  34. If you need to read/write pid_t objects from/to a binary stream, you
  35. don't need any assumptions about pid_t:
  36.  
  37.     FILE *fp;
  38.     pid_t pid;
  39.  
  40.     fread(&pid, sizeof pid, 1, fp);
  41.  
  42. Dan
  43. --
  44. Dan Pop
  45. CERN, CN Division
  46. Email: danpop@mail.cern.ch 
  47. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  48.